package com.juxing.webserver.action.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.juxing.service.userCenter.IUserCenterService;
import com.juxing.service.userCenter.bean.UserBean;
import com.juxing.webserver.action.BaseAction;
import com.juxing.webserver.common.ReturnCodeConstant;

@Controller
@RequestMapping("user")
public class UserAction extends BaseAction {

	@Autowired
	private IUserCenterService userCenterService;
	
	@RequestMapping("queryMyselfInfo.json")
	public ModelAndView queryMyselfInfo(HttpServletRequest request, HttpServletResponse response
			,@RequestParam int userId) {
		
		UserBean user = this.getUserBean(request);
		
		ModelAndView view = this.initSuccessView("user/queryMyselfInfo");
		view.addObject("user", user);
		
		return this.encryptedView(request, response, view);
	}
	
	@RequestMapping("queryOtherInfo.json")
	public ModelAndView queryOtherInfo(HttpServletRequest request, HttpServletResponse response
			,@RequestParam int otherUserId) {
		
		UserBean user = userCenterService.queryByUserId(otherUserId);
		if(user == null) {
			return this.initErrorView(ReturnCodeConstant.USER_NOT_EXIST);
		}
		
		ModelAndView view = this.initSuccessView("user/queryOtherInfo");
		view.addObject("user", user);
		
		return this.encryptedView(request, response, view);
	}
	
}
